package com.softeem.controller;


import com.fasterxml.jackson.databind.ObjectMapper;
import com.softeem.domain.Travle;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.ui.Model;
import com.softeem.service.impl.TravleServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2022-07-01
 */
@Controller
@RequestMapping("/travel")
public class TravleController {

    @Autowired
    TravleServiceImpl service;
    @Autowired
    StringRedisTemplate redisTemplate;

    String traId = "";

    @RequestMapping("/findAllTra")
    public String findAllTra(Model model){

        //查找所有旅游景点
        Travle travle = new Travle();
        List<Travle> travles = travle.selectAll();
        List<Travle> traList = new ArrayList<>();
        for (Travle list : travles) {
            if (list.getTraDid()==1){ //若删除特征码为1则将该景点放入traList中
                traList.add(list);
            }
        }



        model.addAttribute("traList",traList); //将符合条件传回前端traList中

        System.out.println(travles);


        return "/allView";

    }

    @RequestMapping("/findTraPop")
    public String findTraPop(Model model){

        Travle travle = new Travle();
        List<Travle> travles = travle.selectAll();

        List<Travle> travleList = new ArrayList<>();
        for (Travle list : travles) {

            if (list.getTraPid()==1 &&list.getTraDid()==1){ //符合删除特征码为1且热门特征码Pid为1
                travleList.add(list);
            }

        }


        model.addAttribute("traList",travleList);

        System.out.println(travleList);

        return "/popular";

    }

    @RequestMapping("/findTraDic")
    public String findTraDisc(Model model){

        Travle travle = new Travle();
        List<Travle> travles = travle.selectAll();

        List<Travle> travleList = new ArrayList<>();
        for (Travle list : travles) {

            if (list.getTraLid()==1 && list.getTraDid()==1){//符合删除特征码为1且优惠特征码为1
                travleList.add(list);
            }

        }


        model.addAttribute("traList",travleList);

        System.out.println(travleList);

        return "/dicount";

    }


    //realPath+后缀

    @RequestMapping("/findMinPop") //这是在风景欣赏页面的缩小版热门景点
    public String findMinPop(Model model){

        Travle travle = new Travle();
        List<Travle> travles = travle.selectAll();

        List<Travle> travleList = new ArrayList<>();
        for (Travle list : travles) {

            if (list.getTraPid()==1 && list.getTraDid()==1){
                travleList.add(list);
            }

        }


        model.addAttribute("traList",travleList);

        System.out.println(travleList);

        return "/scenery";

    }

    @RequestMapping("/findMinPop2")//这是在视频界面缩小版的热门景点
    public String findMinPop2(Model model){

        Travle travle = new Travle();
        List<Travle> travles = travle.selectAll();

        List<Travle> travleList = new ArrayList<>();
        for (Travle list : travles) {

            if (list.getTraPid()==1 && list.getTraDid()==1){
                travleList.add(list);
            }

        }


        model.addAttribute("traList",travleList);

        System.out.println(travleList);

        return "/video";

    }

    /**
     *     ↓ ↓ ↓   已废弃
     */

    @RequestMapping("/store") //心愿单页面
    //ResponseBody
    public String store(Model model,@ModelAttribute("id")String id){

        Travle travle = new Travle();
        System.out.println("111");
        Travle traList = travle.selectById(id);
        System.out.println(id);
        model.addAttribute("traList",traList);

        return "/store";
     }

     List<Travle> likeList = new ArrayList<>();

     @RequestMapping("/addlikeList")
     public String addlikeList(@ModelAttribute("id")String traId,Model model){
         Travle travle = new Travle();
         Travle list = travle.selectById(traId);
         likeList.add(list);
         model.addAttribute("traList",likeList);
         return "";
      }

      @RequestMapping("/deleteLikeList")
      public String deleteLikeList(@ModelAttribute("id")Integer traId,Model model){

          for (int i = 0 ; i < likeList.size() ; i++){
              if (traId == likeList.get(i).getTraId()){
                  likeList.remove(i);
              }
          }

          model.addAttribute("traList",likeList);

          return "";
       }




}




















